package com.atguigu.ssyx.enums;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Data;
import lombok.Getter;


public enum ActivityType {
    FULL_REDUCTION(1, "满减"),
    FULL_DISCOUNT(2, "满量打折");

    @EnumValue

    private final Integer code;
//        @JsonValue
    private final String comment;

    ActivityType(Integer code, String comment) {
        this.code = code;
        this.comment = comment;
    }

    public Integer getCode() {
        return code;
    }

    public String getComment() {
        return comment;
    }

    // 根据枚举名称获取 code 值
    public static Integer getCodeByName(String name) {
        try {
            return ActivityType.valueOf(name).getCode();
        } catch (IllegalArgumentException e) {
            throw new IllegalArgumentException("非法的活动类型名称: " + name);
        }
    }

    // 根据 code 值获取枚举名称
    public static String getNameByCode(Integer code) {
        for (ActivityType type : values()) {
            if (type.getCode().equals(code)) {
                return type.name();
            }
        }
        throw new IllegalArgumentException("非法的活动类型代码: " + code);
    }


}